import xlrd
import os.path

project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath('GetLoc.py'))))


class BasePageData:
    file = xlrd.open_workbook(project_root + r'\data\BasePage_data.xls')
    dataList = file.sheet_by_name('BasePage').col_values(2)

    def get_base_url(self):
        return self.dataList[1]

    def get_loc_recruitManage(self):
        return self.dataList[2]

    def get_loc_currentTask(self):
        return self.dataList[3]

    def get_loc_employeeManage(self):
        return self.dataList[4]

    def get_loc_systemManage(self):
        return self.dataList[5]

    def get_loc_statistics(self):
        return self.dataList[6]


class SystemManageLoc:
    def __init__(self):
        self.file = xlrd.open_workbook(project_root + r'\data\SystemManage_data.xls')
        self.waysList = self.file.sheet_by_name('ele_loc').col_values(1)
        self.eleValueList = self.file.sheet_by_name('ele_loc').col_values(2)
        self.eleNameList = self.file.sheet_by_name('ele_loc').col_values(0)

    def find_eleValue(self,eleName):
        eleIndex = self.eleNameList.index(eleName)
        return self.waysList[eleIndex], self.eleValueList[eleIndex]

    def change_wayList(self, sheet_name, col_num):
        self.waysList = self.file.sheet_by_name('%s' % sheet_name).col_values(col_num)

    def change_eleValueList(self, sheet_name, col_num):
        self.eleValueList = self.file.sheet_by_name('%s' % sheet_name).col_values(col_num)


class CityPageLoc(SystemManageLoc):
    def __init__(self):
        self.change_wayList('cityPage', 1)
        self.change_eleValueList('cityPage', 2)

    def get_loc_cityName(self):
        return self.waysList[1], self.eleValueList[1]


class CompanyPageLoc(SystemManageLoc):
    def __init__(self):
        self.change_wayList('companyPage', 1)
        self.change_eleValueList('companyPage', 2)

    def get_loc_citySelector(self):
        return self.waysList[1], self.eleValueList[1]

    def get_loc_cityName(self):
        return self.waysList[2], self.eleValueList[2]

    def get_loc_companyName(self):
        return self.waysList[3], self.eleValueList[3]
